ninab222 2.2.2
Loading...
Searching...
No Matches
ninab222.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef NINAB222_H
29#define NINAB222_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
58
63
68
73#define NINAB222_CMD_AT "AT"
74
79#define NINAB222_CMD_CGMI "CGMI"
80#define NINAB222_CMD_CGMM "CGMM"
81#define NINAB222_CMD_CGMR "CGMR"
82#define NINAB222_CMD_CGSN "CGSN"
83#define NINAB222_CMD_GMI "GMI"
84#define NINAB222_CMD_GMM "GMM"
85#define NINAB222_CMD_GMR "GMR"
86#define NINAB222_CMD_GSN "GSN"
87#define NINAB222_CMD_ATI "ATI"
88#define NINAB222_CMD_CSGT "CSGT"
89
94#define NINAB222_CMD_ATW "W"
95#define NINAB222_CMD_ATZ "ATZ"
96#define NINAB222_CMD_ATE "ATE"
97#define NINAB222_CMD_UFACTORY "UFACTORY"
98#define NINAB222_CMD_ATD "D"
99#define NINAB222_CMD_ATS "S"
100#define NINAB222_CMD_CPWROFF "CPWROFF"
101#define NINAB222_CMD_UFWUPD "UFWUPD"
102#define NINAB222_CMD_UMLA "UMLA"
103#define NINAB222_CMD_UMLPO "UMLPO"
104#define NINAB222_CMD_UMRS "UMRS"
105#define NINAB222_CMD_UMRSCFG "UMRSCFG"
106#define NINAB222_CMD_UMRSIG "UMRSIG"
107#define NINAB222_CMD_UMSM "UMSM"
108#define NINAB222_CMD_UMSTAT "UMSTAT"
109#define NINAB222_CMD_UPWRMNG "UPWRMNG"
110#define NINAB222_CMD_UPWRREG "UPWRREG"
111#define NINAB222_CMD_USTOP "USTOP"
112
117#define NINAB222_CMD_ATO "ATO"
118#define NINAB222_CMD_UDATR "UDATR"
119#define NINAB222_CMD_UDATW "UDATW"
120#define NINAB222_CMD_UDBIND "UDBIND"
121#define NINAB222_CMD_UDBINDC "UDBINDC"
122#define NINAB222_CMD_UDCFG "UDCFG"
123#define NINAB222_CMD_UDCP "UDCP"
124#define NINAB222_CMD_UDCPC "UDCPC"
125#define NINAB222_CMD_UDDRP "UDDRP"
126#define NINAB222_CMD_UDLP "UDLP"
127#define NINAB222_CMD_UDSC "UDSC"
128#define NINAB222_CMD_UDSF "UDSF"
129#define NINAB222_CMD_UDUV "UDUV"
130#define NINAB222_CMD_UDWS "UDWS"
131#define NINAB222_CMD_UUDATA "UUDATA"
132#define NINAB222_CMD_UUDPC "UUDPC"
133#define NINAB222_CMD_UUDPD "UUDPD"
134
139#define NINAB222_CMD_UBTDM "UBTDM"
140#define NINAB222_CMD_UBTCM "UBTCM"
141#define NINAB222_CMD_UBTPM "UBTPM"
142#define NINAB222_CMD_UBTSM "UBTSM"
143#define NINAB222_CMD_UBTST "UBTST"
144#define NINAB222_CMD_UBTUC "UBTUC"
145#define NINAB222_CMD_UBTUPE "UBTUPE"
146#define NINAB222_CMD_UBTOTK "UBTOTK"
147#define NINAB222_CMD_UBTND "UBTND"
148#define NINAB222_CMD_UBTI "UBTI"
149#define NINAB222_CMD_UBTD "UBTD"
150#define NINAB222_CMD_UBTBD "UBTBD"
151#define NINAB222_CMD_UBTB "UBTB"
152#define NINAB222_CMD_UBTUB "UBTUB"
153#define NINAB222_CMD_UBTLN "UBTLN"
154#define NINAB222_CMD_UBTLC "UBTLC"
155#define NINAB222_CMD_UBTMSR "UBTMSR"
156#define NINAB222_CMD_UBTMSP "UBTMSP"
157#define NINAB222_CMD_UBTRSS "UBTRSS"
158#define NINAB222_CMD_UBTLQ "UBTLQ"
159#define NINAB222_CMD_UBTLE "UBTLE"
160#define NINAB222_CMD_UBTAD "UBTAD"
161#define NINAB222_CMD_UBTSS "UBTSS"
162#define NINAB222_CMD_UBTWS "UBTWS"
163#define NINAB222_CMD_UBTCFG "UBTCFG"
164#define NINAB222_CMD_UBTLECFG "UBTLECFG"
165#define NINAB222_CMD_UBTDIR "UBTDIR"
166#define NINAB222_CMD_UBTACLC "UBTACLC"
167#define NINAB222_CMD_UBTACLD "UBTACLD"
168#define NINAB222_CMD_UBTLK "UBTLK"
169
174#define NINAB222_PREFIX_SYMBOL_END "\r\n"
175#define NINAB222_PREFIX_SYMBOL_QUERY "?"
176#define NINAB222_PREFIX_SYMBOL_SET_VAL "="
177#define NINAB222_PREFIX_SYMBOL_PLUS "+"
178#define NINAB222_PREFIX_SYMBOL_AND "&"
179#define NINAB222_PREFIX_SYMBOL_SEPARATOR ","
180#define NINAB222_PREFIX_SYMBOL_SPACE " "
181#define NINAB222_PREFIX_SYMBOL_PERCENT "%"
182#define NINAB222_PREFIX_SYMBOL_NULL ""
183#define NINAB222_PREFIX_SYMBOL_QUOTE "\""
184#define NINAB222_PREFIX_SYMBOL_SPS "sps://"
185#define NINAB222_PREFIX_SYMBOL_ZERO "0"
186#define NINAB222_PREFIX_SYMBOL_ONE "1"
187#define NINAB222_PREFIX_SYMBOL_TWO "2"
188
193#define NINAB222_RSP_OK "OK"
194#define NINAB222_RSP_ERROR "ERROR"
195
200#define NINAB222_ECHO_OFF 0
201#define NINAB222_ECHO_ON 1
202
207#define NINAB222_MODE_COMMAND 0
208#define NINAB222_MODE_DATA 1
209#define NINAB222_MODE_EXT_DATA 2
210#define NINAB222_MODE_PPP 3
211
216#define NINAB222_GAP_MODE_NON_PAIRING 0
217#define NINAB222_GAP_MODE_PAIRING 1
218
223#define NINAB222_LR_ROLE_DISABLE 0
224#define NINAB222_LR_ROLE_CENTRAL 1
225#define NINAB222_LR_ROLE_PERIPHERAL 2
226#define NINAB222_LR_ROLE_SIMULTANEOUS 3
227
232#define NINAB222_GAP_MODE_NON_CONN 1
233#define NINAB222_GAP_MODE_CONN 2
234
239#define NINAB222_GAP_MODE_NON_DIS 1
240#define NINAB222_GAP_MODE_LIM_DIS 2
241#define NINAB222_GAP_MODE_GEN_DISC 3
242
247#define NINAB222_ASCII_TABLE_START_NUM 48
248
253#define NINAB222_PIN_STATE_LOW 0
254#define NINAB222_PIN_STATE_HIGH 1
255
261#define NINAB222_TX_DRV_BUFFER_SIZE 100
262#define NINAB222_RX_DRV_BUFFER_SIZE 300
263 // ninab222_cmd
265
270
275
280#define NINAB222_MAP_MIKROBUS( cfg, mikrobus ) \
281 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
282 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
283 cfg.sry = MIKROBUS( mikrobus, MIKROBUS_AN ); \
284 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
285 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
286 cfg.io5 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
287 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
288 // ninab222_map // ninab222
291
296typedef struct
297{
298 // Output pins
299 digital_out_t rst;
300 digital_out_t cs;
301 digital_out_t io5;
302 digital_out_t sry;
303
304 // Input pins
305 digital_in_t rts;
306
307 // Modules
308 uart_t uart;
309
310 // Buffers
313
314} ninab222_t;
315
320typedef struct
321{
322 // Communication gpio pins
323 pin_name_t rx_pin;
324 pin_name_t tx_pin;
325
326 // Additional gpio pins
327 pin_name_t sry;
328 pin_name_t rst;
329 pin_name_t cs;
330 pin_name_t io5;
331 pin_name_t rts;
332
333 // Static variable
334 uint32_t baud_rate;
336 uart_data_bits_t data_bit;
337 uart_parity_t parity_bit;
338 uart_stop_bits_t stop_bit;
339
341
346typedef enum
347{
350
352
358
369
384
397err_t ninab222_generic_write ( ninab222_t *ctx, uint8_t *data_in, uint16_t len );
398
411err_t ninab222_generic_read ( ninab222_t *ctx, uint8_t *data_out, uint16_t len );
412
422
434err_t ninab222_write_cmd ( ninab222_t *ctx, uint8_t *command );
435
447err_t ninab222_write_sys_cmd ( ninab222_t *ctx, uint8_t *command );
448
462err_t ninab222_write_cmd_param ( ninab222_t *ctx, uint8_t *command, uint8_t *param );
463
476err_t ninab222_inquire_cmd ( ninab222_t *ctx, uint8_t *command );
477
490
503
516
529err_t ninab222_set_start_mode ( ninab222_t *ctx, uint8_t start_mode );
530
543
556err_t ninab222_set_enter_mode ( ninab222_t *ctx, uint8_t enter_mode );
557
571err_t ninab222_set_echo ( ninab222_t *ctx, uint8_t echo_en );
572
585err_t ninab222_set_device_name ( ninab222_t *ctx, uint8_t *device_name );
586
600
613err_t ninab222_set_le_role ( ninab222_t *ctx, uint8_t le_role );
614
628
642
656
669err_t ninab222_set_pairing_mode ( ninab222_t *ctx, uint8_t p_mode );
670
683err_t ninab222_set_connectability ( ninab222_t *ctx, uint8_t c_mode );
684
697
710err_t ninab222_set_discoverability ( ninab222_t *ctx, uint8_t d_mode );
711
724
741
755err_t ninab222_remote_peer ( ninab222_t *ctx, uint8_t *domain );
756
770
779void ninab222_clear_to_send ( ninab222_t *ctx, uint8_t cts );
780
790
799void ninab222_set_sry_pin ( ninab222_t *ctx, uint8_t state );
800
809void ninab222_set_io5_pin ( ninab222_t *ctx, uint8_t state );
810
811#ifdef __cplusplus
812}
813#endif
814#endif // NINAB222_H
815 // ninab222
817
818// ------------------------------------------------------------------------ END
#define NINAB222_TX_DRV_BUFFER_SIZE
NINA-B222 driver buffer size.
Definition ninab222.h:261
#define NINAB222_RX_DRV_BUFFER_SIZE
Definition ninab222.h:262
void ninab222_set_io5_pin(ninab222_t *ctx, uint8_t state)
NINA-B222 set IO5 pin state function.
err_t ninab222_get_peers_list(ninab222_t *ctx)
NINA-B222 get low energy role function.
err_t ninab222_rst_def_cfg(ninab222_t *ctx)
NINA-B222 set to factory defined configuration function.
err_t ninab222_periph_pairing_cfg(ninab222_t *ctx)
NINA-B222 default remote peer function.
err_t ninab222_get_discoverability(ninab222_t *ctx)
NINA-B222 sets discoverability mode function.
err_t ninab222_generic_read(ninab222_t *ctx, uint8_t *data_out, uint16_t len)
NINA-B222 data reading function.
err_t ninab222_set_bt_intf(ninab222_t *ctx)
NINA-B222 store current configuration function.
err_t ninab222_init(ninab222_t *ctx, ninab222_cfg_t *cfg)
NINA-B222 initialization function.
err_t ninab222_set_discoverability(ninab222_t *ctx, uint8_t d_mode)
NINA-B222 sets discoverability mode function.
err_t ninab222_set_start_mode(ninab222_t *ctx, uint8_t start_mode)
NINA-B222 sets start mode function.
err_t ninab222_write_cmd(ninab222_t *ctx, uint8_t *command)
NINA-B222 command writing function.
err_t ninab222_get_le_role(ninab222_t *ctx)
NINA-B222 get low energy role function.
void ninab222_set_sry_pin(ninab222_t *ctx, uint8_t state)
NINA-B222 set SRY pin state function.
err_t ninab222_remote_peer(ninab222_t *ctx, uint8_t *domain)
NINA-B222 default remote peer function.
err_t ninab222_set_pairing_mode(ninab222_t *ctx, uint8_t p_mode)
NINA-B222 sets pairing mode function.
void ninab222_hw_reset(ninab222_t *ctx)
NINA-B222 HW reset function.
err_t ninab222_get_start_mode(ninab222_t *ctx)
NINA-B222 get start mode function.
err_t ninab222_get_device_name(ninab222_t *ctx)
NINA-B222 get device name function.
err_t ninab222_set_enter_mode(ninab222_t *ctx, uint8_t enter_mode)
NINA-B222 sets enter mode function.
err_t ninab222_reboot_dce(ninab222_t *ctx)
NINA-B222 reboot DCE function.
err_t ninab222_inquire_cmd(ninab222_t *ctx, uint8_t *command)
NINA-B222 inquire command function.
err_t ninab222_set_le_role(ninab222_t *ctx, uint8_t le_role)
NINA-B222 sets low energy role function.
err_t ninab222_set_echo(ninab222_t *ctx, uint8_t echo_en)
NINA-B222 set echo function.
err_t ninab222_write_sys_cmd(ninab222_t *ctx, uint8_t *command)
NINA-B222 system command writing function.
err_t ninab222_set_default_cfg(ninab222_t *ctx)
NINA-B222 sets the default configuration function.
err_t ninab222_set_connectability(ninab222_t *ctx, uint8_t c_mode)
NINA-B222 sets connectabilit mode function.
uint8_t ninab222_request_to_send(ninab222_t *ctx)
NINA-B222 get request to send pin state function.
err_t ninab222_set_device_name(ninab222_t *ctx, uint8_t *device_name)
NINA-B222 sets device name function.
void ninab222_clear_to_send(ninab222_t *ctx, uint8_t cts)
NINA-B222 set clear to send pin state function.
void ninab222_cfg_setup(ninab222_cfg_t *cfg)
NINA-B222 configuration object setup function.
err_t ninab222_generic_write(ninab222_t *ctx, uint8_t *data_in, uint16_t len)
NINA-B222 data writing function.
err_t ninab222_write_cmd_param(ninab222_t *ctx, uint8_t *command, uint8_t *param)
NINA-B222 command - parameter writing function.
err_t ninab222_get_connectability(ninab222_t *ctx)
NINA-B222 sets connectabilit mode function.
err_t ninab222_get_info(ninab222_t *ctx)
NINA-B222 get module-info function.
ninab222_return_value_t
NINA-B222 Click return value data.
Definition ninab222.h:347
@ NINAB222_OK
Definition ninab222.h:348
@ NINAB222_ERROR
Definition ninab222.h:349
NINA-B222 Click configuration object.
Definition ninab222.h:321
pin_name_t rts
Definition ninab222.h:331
uint32_t baud_rate
Definition ninab222.h:334
pin_name_t io5
Definition ninab222.h:330
bool uart_blocking
Definition ninab222.h:335
uart_data_bits_t data_bit
Definition ninab222.h:336
pin_name_t tx_pin
Definition ninab222.h:324
pin_name_t rx_pin
Definition ninab222.h:323
uart_stop_bits_t stop_bit
Definition ninab222.h:338
pin_name_t sry
Definition ninab222.h:327
uart_parity_t parity_bit
Definition ninab222.h:337
pin_name_t rst
Definition ninab222.h:328
pin_name_t cs
Definition ninab222.h:329
NINA-B222 Click context object.
Definition ninab222.h:297
digital_out_t cs
Definition ninab222.h:300
digital_out_t io5
Definition ninab222.h:301
uart_t uart
Definition ninab222.h:308
digital_out_t sry
Definition ninab222.h:302
digital_in_t rts
Definition ninab222.h:305
digital_out_t rst
Definition ninab222.h:299
uint8_t uart_tx_buffer[NINAB222_TX_DRV_BUFFER_SIZE]
Definition ninab222.h:312
uint8_t uart_rx_buffer[NINAB222_RX_DRV_BUFFER_SIZE]
Definition ninab222.h:311